# -*- coding: utf-8 -*-
# @Author  : pony.guan
# @Time    : 2021/12/2 10:33
# Description:
import json

import requests


"""
iwms stations: XSYS100~XSYS107
"""

# iwms工作人工创建， iwms播种墙人工创建

iwsm_stations = [f'XSYS{i}' for i in range(100, 108)]

points = [
    (6650, 92790),
    (9860, 92790),
    (13080, 92790),
    (16230, 92790),
    (29110, 94330),
    (56470, 94330),
    (82190, 94330),
]

# 添加取放货点 & 创建ess工作站管理iwms中的工作站

url = 'http://172.20.110.15:9000/model/updateModelNotSafe'
headers = {
    "Content-Type": "application/json",
}
for point, station_code in zip(points, iwsm_stations):
    x, y = point
    code = f"LT_LABOR:POINT:{x}:{y}"
    point_code = f"POINT:{x}:{y}"
    data = {
        "id": "1711248363040541696",
        "code": code,
        "updated": "1631973612824",
        "location": {
            "id": "1711248363040541696",
            "code": code,
            "locationTypeCode": "LT_LABOR",
            "position": {
                "x": f"{x}",
                "y": f"{y}",
                "z": "0"
            },
            "link": [
                {
                    "pointCode": point_code,
                    "robot2mapTheta": "0",
                    "container2mapTheta": "0"
                }
            ],
            "isLocked": False,
            "isAbnormal": False,
            "abnormalReason": "NONE",
            "storageTag": "",
            "containerCode": "",
            "actionFailedCount": {}
        }
    }
    print('开始创建取放货点:', point)
    r = requests.post(url=url, data=json.dumps(data), headers=headers)

    assert r.json()['code'] in [0, '0']
    print('创建取放货点:', point, '成功')

    data1 = {
        "id": "1711248438992048640",
        "code": station_code,
        "updated": "1631974502789",
        "additionData": {
            "info": ""
        },
        "locationActor": {
            "id": "1711248438992048640",
            "code": station_code,
            "boundLocation": {
                code: True
            },
            "boxType": "GREY_BOX",
            "putawayByTask": False,
            "isScanBeforeLoad": False,
            "isRdkConveyorMode": False,
            "canSwitchInOrOut": False,
            "locationCodeToBack": {},
            "groupOwner": {
                "group1": "MAN"
            },
            "group": {
                "group1": {
                    "locationCode": []
                }
            },
            "nonWorkingLocation": [],
            "highestTierWhenOutbound": 0,
            "highestTierWhenInbound": 0,
            "tryActionRule": {
                "ignoreAllChecks": False,
                "ignoreCheckContainer": False,
                "containerNeedTheSameForLoad": False,
                "needContainerForLoad": False,
                "locationNeedEmptyForUnload": False,
                "unloadBlockedHandling": "TASK_AWAITING",
                "checkGroupOwner": False,
                "unloadNeedToConfirm": False,
                "unloadConfirmValidTimeMs": "0",
                "forkHitDetectionAction": [],
                "forkHitDetectionSafetyDistance": "0",
                "robotActionDistanceErrorRange": "0"
            },
            "endActionRule": {
                "defaultFailedHandling": "TASK_SUSPEND_ROBOT_AWAITING",
                "scanFailedHandling": "TASK_SUSPEND_ROBOT_AWAITING",
                "loadFailedHandling": "TASK_SUSPEND_ROBOT_AWAITING",
                "unloadFailedHandling": "TASK_SUSPEND_ROBOT_AWAITING",
                "manualFailedHandling": "TASK_SUSPEND_ROBOT_AWAITING",
                "ignoreScanResult": False,
                "scanResultCorrectionData": False,
                "locationAbnormalLoadFailedCount": 0,
                "isOutsideAsRobotUnload": False,
                "prepareAction": False,
                "leaveAsNoTask": False,
                "forceCheckTaskOfPutawayAfterScan": False,
                "locationAbnormalAfterScanFailed": False
            },
            "callRobotRule": {
                "allowedCallRobot": True,
                "defaultCallRobotLocation": [],
                "callRobotAfterLoadLocation": [],
                "totalCallRobotLimit": 0,
                "callRobotLimitPerLocation": 0,
                "onlyInbound": False
            },
            "nonRobotActionRule": {
                "isAllowedNonRobotLoad": True,
                "isAllowedNonRobotUnload": True,
                "isInsideAsNonRobotLoad": True,
                "isOutsideAsNonRobotUnload": True,
                "isAllowedNotSpecifyingContainer": True,
                "overwrittenLocationAsNonRobotLoad": []
            },
            "kubotLabor": True
        }
    }

    r1 = requests.post(url=url, data=json.dumps(data1), headers=headers)

    print('开始添加人工工作站&映射:', '点位:', point,  '两边的station_code均为:', station_code)
    assert r.json()['code'] in [0, '0']
    print('添加人工工作站&映射成功:', point, '成功', )
# 添加工作站

# 重启actor
# restartController
# oneClickCreateMockKubot
# 系统恢复

"""

"""
